/*
 * 文件名：PostDaoImpl.java
 * 版权：Copyright 2007-2015 517na Tech. Co. Ltd. All Rights Reserved. 
 * 描述： PostDaoImpl.java
 * 修改人：yanshu
 * 修改时间：2015年12月24日
 * 修改内容：新增
 */
package com.feichuang.chineseWoodCarving.dao.impl;

import java.util.Date;
import java.util.List;

import org.springframework.stereotype.Component;

import com.feichuang.chineseWoodCarving.dao.IPostDao;
import com.feichuang.chineseWoodCarving.interceptor.BeanUtils;
import com.feichuang.chineseWoodCarving.model.MPagerRequestVo;
import com.feichuang.chineseWoodCarving.model.MPost;

/**
 * TODO 添加类的一句话简单描述.
 * <p>
 * TODO 详细描述
 * <p>
 * TODO 示例代码
 * 
 * <pre>
 * </pre>
 * 
 * @author yanshu
 */
@Component("postDao")
public class PostDaoImpl extends BaseDaoImpl implements IPostDao {

    /**
     * {@inheritDoc}.
     */
    @Override
    public boolean insertPost(MPost post) {
        post.setAddTime(new Date());
        BeanUtils.notNull(post);
        this.sqlSession.insert("com.feichuang.chineseWoodCarving.dao.IPostDao.insertPost", post);
        return true;
    }

    /**
     * {@inheritDoc}.
     */
    @Override
    public List<MPost> selectPost(MPost post) {
        List<MPost> listPost = this.sqlSession.selectList("com.feichuang.chineseWoodCarving.dao.IPostDao.selectPost", post);
        return listPost;
    }

    /**
     * {@模糊查询}. com.feichuang.chineseWoodCarving.dao.IPostDao.selectPostFuzzyQuer
     */
    @Override
    public List<MPost> selectPostFuzzyQuer(MPost post) {
        List<MPost> listPost = this.sqlSession.selectList("com.feichuang.chineseWoodCarving.dao.IPostDao.selectPostFuzzyQuer", post);
        return listPost;
    }

    /**
     * {@inheritDoc}.
     */
    @Override
    public boolean deletePostByID(MPost post) {
        this.sqlSession.update("com.feichuang.chineseWoodCarving.dao.IPostDao.deletePostByID", post);
        return true;
    }

    /**
     * {@inheritDoc}.
     */
    @Override
    public MPost selectPostByID(MPost post) {
        return this.sqlSession.selectOne("com.feichuang.chineseWoodCarving.dao.IPostDao.selectPostByID", post);
    }

    /**
     * {@inheritDoc}.
     */
    @Override
    public int selectPostCountForPage(MPost post) {
        // TODO Auto-generated method stub
        if (post == null) {
            return this.sqlSession.selectOne("com.feichuang.chineseWoodCarving.dao.IPostDao.selectPostCountForPage1");
        } else {
            return this.sqlSession.selectOne("com.feichuang.chineseWoodCarving.dao.IPostDao.selectPostCountForPage", post);
        }
    }

    /**
     * {@inheritDoc}.
     */
    @Override
    public List<MPost> selectPostForPage(MPagerRequestVo<MPost> pageRequest) {
        // TODO Auto-generated method stub
        return this.sqlSession.selectList("com.feichuang.chineseWoodCarving.dao.IPostDao.selectPostForPage", pageRequest);
    }

    /**
     * {@inheritDoc}.
     */
    @Override
    public boolean updatePost(MPost post) {
        // TODO Auto-generated method stub
        this.sqlSession.update("com.feichuang.chineseWoodCarving.dao.IPostDao.updatePost", post);
        return true;
    }
}
